package com.atguigu.gulimall.product.sync;


import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

public class ThreadDemo4 {
    public static void main(String[] args) {
        //写时复制技术解决多线程不安全问题
        List<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 300; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0, 4));
                System.out.println(list);
            }, String.valueOf(i)).start();
        }

    }
}
